home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / uucosr10 / event.c < prev    next >
C/C++ Source or Header  |  1991-05-25  |  5KB  |  265 lines

  1. #include <stdio.h>
  2. #include <obdefs.h>
  3. #include <gemdefs.h>
  4. #include "keycodes.h"
  5.  
  6. #include "uucoder.h" 
  7.  
  8. extern OBJECT *menubar;
  9.  
  10. #ifndef PATHSIZ
  11. #define PATHSIZ    128
  12. #endif
  13.  
  14. #define ding()    putch(0x07)
  15.  
  16. char filename[PATHSIZ];
  17.  
  18. extern int split;
  19. extern int fileln;
  20.  
  21. /*
  22.  * function: sho_dialog(index)
  23.  * returns:  index of object used to exit a form
  24.  * description: Find an object in the resource tree based on index.
  25.  *         Center it, draw it, interact with it, clean up, return. 
  26.  */
  27.  
  28. int sho_dialog(index)
  29.     int index;
  30.     {
  31.     OBJECT *tree;
  32.     int x,y,w,h,ret;
  33.     rsrc_gaddr(R_TREE,index,&tree);
  34.     form_center(tree, &x, &y, &w, &h);
  35.     form_dial(FMD_START,1,1,1,1,x,y,w,h);
  36.     form_dial(FMD_GROW,1,1,1,1,x,y,w,h);
  37.     objc_draw(tree, 0, 20, x, y, w, h);
  38.     ret = form_do(tree,-1);
  39.     form_dial(FMD_SHRINK,1,1,1,1,x,y,w,h);
  40.     form_dial(FMD_FINISH,1,1,1,1,x,y,w,h);
  41.     tree[ret].ob_state = NORMAL;
  42.     return ret;
  43.     }
  44.  
  45.  
  46.  
  47. /*
  48.  * function: disp_process
  49.  * returns:  nothing 
  50.  * description: Draw a progress report box on the screen. The companion
  51.  *              routine erase_process() does the cleanup.
  52.  *
  53.  */
  54.  
  55. void disp_process(filename)
  56.     char *filename;
  57.     {
  58.     int x,y,w,h,ret;
  59.     OBJECT *tree;
  60.     char *p;
  61.     rsrc_gaddr(R_TREE,PROCESS,&tree);
  62.     /* find the base filename and copy it into the TEDINFO */
  63.     for (p = filename + strlen(filename);p > filename;p--)
  64.         {
  65.         if (*p == ':') break;
  66.         if (*p == '\\') break;
  67.         }
  68.     p++;
  69.     strcpy(((TEDINFO *)tree[WORKFILE].ob_spec)->te_ptext,p);
  70.     form_center(tree, &x, &y, &w, &h);
  71.     form_dial(FMD_START,1,1,1,1,x,y,w,h);
  72.     form_dial(FMD_GROW,1,1,1,1,x,y,w,h);
  73.     objc_draw(tree, 0, 20, x, y, w, h);
  74.     }
  75.  
  76. /*
  77.  * function: erase_process
  78.  * returns:  void
  79.  * description: Erase the process report from the screen.
  80.  *
  81.  */
  82. void erase_process()
  83.     {
  84.     int x,y,w,h;
  85.     OBJECT *tree;
  86.     rsrc_gaddr(R_TREE,PROCESS,&tree);
  87.     form_center(tree, &x, &y, &w, &h);
  88.     form_dial(FMD_SHRINK,1,1,1,1,x,y,w,h);
  89.     form_dial(FMD_FINISH,1,1,1,1,x,y,w,h);
  90.     }
  91.  
  92.  
  93. /*
  94.  * function: evalmessage()
  95.  * returns:  void
  96.  * description: handles AES message events; this is a separate function
  97.  *              to avoid cluttering up main_event.
  98.  *
  99.  */
  100.  
  101. void evalmessage(msg_buf)
  102.     WORD msg_buf[];
  103.     {
  104.     register int i;
  105.     if (msg_buf[0] != MN_SELECTED)
  106.         {
  107.         ding();
  108.         return();
  109.         }
  110.     menu_tnormal(menubar,msg_buf[3],TRUE);
  111.     menu_tnormal(menubar,msg_buf[4],TRUE);
  112.     switch(msg_buf[4])
  113.         {
  114.         case ABOUT:
  115.             show_about();
  116.             break;
  117.         case DECODE:
  118.             if (fsel("UUDecode a file","*.U??","",filename))
  119.                 {
  120.                 decode(filename);
  121.                 erase_process();
  122.                 }
  123.             break;
  124.         case ENCODE:
  125.             if (fsel("UUEncode a file","*.*","",filename))
  126.                 {
  127.                 encode(filename);
  128.                 erase_process();
  129.                 }
  130.             break;
  131.         case CODEHELP:
  132.             sho_dialog(HELPCODE,-1);    
  133.             break;
  134.         case CFGHELP:
  135.             sho_dialog(HELPCFG,-1);    
  136.             break;
  137.         case QUIT:
  138.             quit();
  139.             break;
  140.         case MAX5K:
  141.         case MAX10K:
  142.         case MAX32K:
  143.         case MAX60K:
  144.         case MAX100K:
  145.             split = TRUE;
  146.             for (i=MAX5K; i<=MAX100K;i++)
  147.                 menu_ichek(menubar,i,FALSE);
  148.             menu_ichek(menubar,msg_buf[4],TRUE);
  149.             switch(msg_buf[4])
  150.                 {
  151.                 case MAX5K:
  152.                     /* 62 char per line */
  153.                     fileln = 5*(1024/62);
  154.                     break;
  155.                 case MAX10K:
  156.                     fileln = 10*(1024/62);
  157.                     break;
  158.                 case MAX32K:
  159.                     fileln = 32*(1024/62);
  160.                     break;
  161.                 case MAX60K:
  162.                     fileln = 60*(1024/62);
  163.                     break;
  164.                 case MAX100K:
  165.                     fileln = 100*(1024/62);
  166.                     break;
  167.                 default:
  168.                     break;
  169.                 }
  170.             break;
  171.         default:
  172.             break;
  173.         }
  174.     }
  175.  
  176.  
  177. /*
  178.  * function: evalkeybd(keycode)
  179.  * returns:  void
  180.  * description: handle an AES keyboard event
  181.  *
  182.  */
  183.  
  184. void evalkeybd(keycode)
  185.     unsigned int keycode;
  186.     {
  187.     switch (keycode)
  188.         {
  189.         case ALT_D:
  190.             if (fsel("UUDecode a file","*.U??","",filename))
  191.                 {
  192.                 decode(filename);
  193.                 erase_process();
  194.                 }
  195.             break;
  196.         case ALT_E:
  197.             if (fsel("UUEncode a file","*.*","",filename))
  198.                 {
  199.                 encode(filename);
  200.                 erase_process();
  201.                 }
  202.             break;
  203.         case ALT_H:
  204.         case KEY_HELP:
  205.             sho_dialog(HELPCODE,-1);    
  206.             break;
  207.         case ALT_X:
  208.         case ALT_Q:
  209.             quit();
  210.         default:
  211.             ding();
  212.             break;
  213.         }
  214.     }
  215.  
  216.  
  217.  
  218. /*
  219.  * function: main_event
  220.  * returns:  void
  221.  * description: the primary event loop for the application
  222.  *
  223.  */
  224.  
  225. void main_event()
  226.     {
  227.     WORD    mevx,mevy,butstate,mevbut,keystate,keycode,mbreturn,
  228.         msg_buf[8],event;
  229.     butstate=1;
  230.     for(;;)    /* forever */
  231.         {
  232.         /* the event loop */
  233.         filename[0] = '\0';
  234.         event = evnt_multi(MU_KEYBD|MU_MESAG,
  235.             0,
  236.             0,
  237.             butstate,
  238.             0,
  239.             0,0,0,0,
  240.             0,
  241.             0,0,0,0,
  242.             msg_buf,
  243.             0,0,
  244.             &mevx,&mevy,
  245.             &mevbut,
  246.             &keystate,
  247.             &keycode,
  248.             &mbreturn);
  249.  
  250.         switch (event)
  251.             {
  252.             case MU_MESAG:
  253.                 evalmessage(msg_buf);
  254.                 break;
  255.             case MU_KEYBD:
  256.                 evalkeybd(keycode);
  257.                 break;
  258.             default:
  259.                 ding();
  260.                 break; /* do nothing */
  261.             }
  262.         } 
  263.     }
  264.  
  265.